package org.rain.common.util.json.status;

import org.rain.common.util.json.AbsJsonState;
import org.rain.common.util.json.JsonFsm;

/**
 * created by yangtong on 2025/4/14 22:41:56
 * <br/>
 * 准备获取json键值对的key
 */
public class ExpectKeyState extends AbsJsonState {
    @Override
    public void handleNonWhitespace(JsonFsm fsm, char c) {
        //准备读取key，标准json的key都是以
        if (c == '"') {
            //读取到了'"'，切换到IN_KEY，表示正在读取key
            fsm.changeState(IN_KEY);
            fsm.cleanBuffer();
            return;
        } else if (c == '}' || c == ']') {
            if (fsm.deNesting() == 0) {
                fsm.changeState(END);
            }
            return;
        }
        throw new RuntimeException("意料之外的字符，期望读到【\"】，实际读到【" + c + "】");
    }
}
